package com.mokairui.share_model__routines.protective_pause.basic;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;

/**
 * @Description 保护型暂停模式
 * @Author Mokairui
 * @Since 2021/7/20
 */
@Slf4j(topic = "c.ProtectPause")
public class ProtectPause {
    public static void main(String[] args) {
        GuardedObject guardedObject = new GuardedObject();
        new Thread(() -> {
            // 等待结果
            log.debug("等待结果");
            List<String> list = (List<String>) guardedObject.get(5000);
            log.debug("结果大小：{}", list.size());
        }, "t1").start();

        new Thread(() -> {
            log.debug("执行下载");
            List<String> list = Arrays.asList("a", "b", "c");
            guardedObject.complete(list);
        }, "t2").start();
    }
}
